<style>
.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
.order-time-bg{background-color:#1E9FFF;color:white;padding:0px 5px;}
.order-num span{display:inline-block;min-width:25px;margin:0px 2px;text-align:center;}
.dress_line_code{margin-top:6px;}
.dress_line_code textarea{height:100px;padding:6px;width:578px}
.submit_block{padding-left:230px;}
.checkInNumSpan{text-decoration:underline;}
.checkin_ret{text-align:center;padding-top:30px;}
.scan_code_ret{color:red;font-weight:bold;margin-bottom:6px;}
.defective_reason{padding:3px 2px;}
.defective_reason input{padding:2px 4px;}
.layui-table-cell{line-height:21px;}
</style>
<div class="fixed-bar">
	<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search-optable">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">订单号</label>
			<div class="layui-input-inline">
				<input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
			</div>
		</div>
		{if env('env_site') == 'riwei' }
		<div class="layui-inline">
			<label class="layui-form-label">客户单号</label>
			<div class="layui-input-inline">
				<input type="text" name="ext_id" lay-verify="" placeholder="输入客户单号" class="layui-input">
			</div>
		</div>
		{/if}
		<div class="layui-inline">
			<label class="layui-form-label">SKU</label>
			<div class="layui-input-inline">
				<input type="text" name="sku" lay-verify="" placeholder="输入SKU" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">所属工厂</label>
			<div class="layui-input-inline">
				{:Form::select('factory_id', '', $factoryKV, '', '')}
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">订单状态</label>
			<div class="layui-input-inline">
				{:Form::select('order_status', '', ['' => '请选择', 1=>'未采购', 2=>'已采购', 3=>'已裁床', 4=>'已车缝', 5=>'已后整', 6=>'已出货', 7=>'已完成'], '', '')}
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">下单日期</label>
			<div class="layui-input-inline">
				<input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择下单日期" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">总完日期</label>
			<div class="layui-input-inline">
				<input type="text" name="over_date_range" readonly="" id="over_date_range" lay-verify="" placeholder="选择完成日期" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">裁床日期</label>
			<div class="layui-input-inline">
				<input type="text" name="caichuang_over_date_range" readonly="" id="caichuang_over_date_range" lay-verify="" placeholder="选择裁床完成日期" class="layui-input">
			</div>
		</div>
        <div class="layui-inline">
			<label class="layui-form-label">尾完日期</label>
			<div class="layui-input-inline">
				<input type="text" name="tail_over_time" readonly="" id="tail_over_time" lay-verify="" placeholder="选择完成日期" class="layui-input">
			</div>
		</div>
        <div class="layui-inline">
			<label class="layui-form-label">发货子单状态</label>
			<div class="layui-input-inline">
				{:Form::select('delivery_status', '', ['' => '请选择',1=>'未全部入仓', 2=>'已全部入仓', 3=>'含已收货', 4=>'含已退货', 5=>'含待发货'], '', '')}
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">断码筛选</label>
			<div class="layui-input-inline">
				{:Form::select('break_type', '', [''=>'全部','1'=>'正常','2'=>'将断码','3'=>'已断码'],'','')}
			</div>
		</div>
		<div class="layui-inline">
			<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
            <button type="button" class="layui-btn layui-btn-primary hisi-export">导出</button>
		</div>
	</div>
	</form>
</div>

<table id="dataTable" lay-filter='dataTable'></table>

{include file="system@block/layui" /}

<script type="text/html" id="picTpl">
    <span class="lay-pic-container" src="{{ d.sInfo.pic }}">
		<img src="{{ d.sInfo.ori_pic }}" class="lay-pic">
		{{# if(d.status==99){ }}
			<span class="sign"><img src="/static/system/image/sign_delete.png"></span>
		{{# }else if(d.status==2){ }}
			<span class="sign"><img src="/static/system/image/sign_over.png"></span>
		{{# } }}
	</span>
</script>
<script type="text/html" id="skuTpl">
	{{# if(d.break_code != ''){ }}
	<span class="red">{{ d.break_code }}</span>
	<br>
	{{# } }}
    <span class="copy-item">{{ d.client_ordernum }}</span> <span class="layui-badge layui-bg-blue">{{ layui.tool.formatOrderOType(d.o_type) }}</span><span class="layui-badge layui-bg-orange">{{ layui.tool.formatOrderType(d.type) }}</span><br>
	{if env('env_site') == 'riwei' }
	<span class="copy-item">{{ d.ext_id }}</span> <br>
	{/if}
	<span class="copy-item">{{ d.sku }}</span> <br>
    {{ d.shipment_time_diff }} <br>
    {{ d.create_time_diff }} <br>
	{{ orderFrom[d.is_auto_import] }}<br />
    {{# if(d.status == 99){ }}<span class="layui-badge">{{ d.delete_text }}</span> {{# } }}
</script>
<script type="text/html" id="factoryTpl">
	工厂：{{ d.factory_name }}<br>
	分组：{{ d.group_name }}
</script>
<script type="text/html" id="orderNumTpl">
	<div class="order-num">
	{{# var totalCH=0;}}
	{{# for(var i in d.osList){ }}
    	{{ d.osList[i].size_name }}：<span title="下单数">{{ d.osList[i].order_count }}</span>/<span title="裁床数">{{ d.osList[i].shicai_count }}</span>/<span title="车间数">{{ d.osList[i].jiaohuo_count }}</span>/<span title="后整数">{{ d.osList[i].jiaohuo_tail_count }}</span>/<span title="打包数">{{ d.osList[i].delivery_count }}</span>/<span title="已出货数">{{ d.osList[i].daohuo_count }}</span>/<span title="未出货数">{{# if(d.osList[i].delivery_count-d.osList[i].daohuo_count>0){ }}{{# totalCH = totalCH+d.osList[i].delivery_count-d.osList[i].daohuo_count}}{{ d.osList[i].delivery_count-d.osList[i].daohuo_count }} {{# }else{ }} 0 {{# } }}</span> <br>
	{{# } }}
	总数：<span title="总下单数">{{ d.osStat.order_count }}</span>/<span title="总裁床数">{{ d.osStat.shicai_count }}</span>/<span title="总车间数">{{ d.osStat.jiaohuo_count }}</span>/<span title="总后整数">{{ d.osStat.jiaohuo_tail_count }}</span>/<span title="总打包数">{{ d.osStat.delivery_count }}</span>/<span title="总已出货数">{{ d.osStat.daohuo_count }}</span>/<span title="总未出货数">{{ totalCH }}</span>
	</div>
</script>
<script type="text/html" id="orderTimeTpl">
    <div class="{{# if(d.create_time > 0){ }}order-time-bg{{# } }}">下单：{{# if(d.create_time > 0){ }} {{ layui.util.toDateString(d.create_time * 1000) }} {{# } }}</div>
	<div class="{{# if(d.shipment_time > 0){ }}order-time-bg{{# } }}">货期：{{# if(d.shipment_time > 0){ }} {{ layui.util.toDateString(d.shipment_time * 1000) }} {{# } }}</div>    
	<div class="{{# if(d.caigou_over_time > 0){ }}order-time-bg{{# } }}">采购：{{# if(d.caigou_over_time > 0){ }} {{ layui.util.toDateString(d.caigou_over_time * 1000) }} {{# } }}</div>
    <div class="{{# if(d.caichuang_over_time > 0){ }}order-time-bg{{# } }}">裁床：{{# if(d.caichuang_over_time > 0){ }} {{ layui.util.toDateString(d.caichuang_over_time * 1000) }} {{# } }}</div>
    <div class="{{# if(d.chejian_over_time > 0){ }}order-time-bg{{# } }}">车间：{{# if(d.chejian_over_time > 0){ }} {{ layui.util.toDateString(d.chejian_over_time * 1000) }} {{# } }}</div>
    <div class="{{# if(d.tail_over_time > 0){ }}order-time-bg{{# } }}">尾部：{{# if(d.tail_over_time > 0){ }} {{ layui.util.toDateString(d.tail_over_time * 1000) }} {{# } }}</div>
    <div class="{{# if(d.over_time > 0){ }}order-time-bg{{# } }}">总完：{{# if(d.over_time > 0){ }} {{ layui.util.toDateString(d.over_time * 1000) }} {{# } }}</div>
</script>
<script type="text/html" id="orderUserTpl">
	{{ d.caigou_user_name }} <br>
    {{ d.caichuang_user_name }}
</script>
<script type="text/html" id="stockTpl">
	{{# for(var i in d.stockList){ }}
    	{{ d.stockList[i].size_name }}： {{ d.stockList[i].available_count }} / {{ d.stockList[i].defective_count}} <br>
	{{# } }}
</script>
<script type="text/html" id="otherStockTpl">
	{{# if(d.otherStockCount>0){ }}
		{{# for(var i in d.otherStockList){ }}
			{{ d.otherStockList[i].size_name }}： {{ d.otherStockList[i].available_count }} / {{ d.otherStockList[i].defective_count}} <br>
		{{# } }}
		{{# if(d.otherStockList.length>0){ }}
			<a href="javascript:void(0)" data-url="{:url('stockCheckOut')}?order_id={{ d.id }}" data-id="{{ d.id }}" data-ordernum='{{ d.client_ordernum}}' data-json='{{ d.otherStockList_json }}' title="调用库存" class="layui-btn layui-btn-warm layui-btn-sm tail-stock-out">调用库存</a>
		{{# } }}
	{{# } }}
</script>
<script type="text/html" id="buttonTpl">
	<div style="line-height:35px;">
		<a href="javascript:void(0)" data-url="{:url('stockCheckIn')}?order_id={{ d.id }}" data-id="{{ d.id }}" stocktype='not_defective' data-ordernum='{{ d.client_ordernum}}' data-json='{{ d.osJson }}' title="库存录入" class="layui-btn layui-btn-normal layui-btn-sm tail-stock-outin">库存录入</a><br>
		<a href="javascript:void(0)" data-url="{:url('stockCheckIn')}?order_id={{ d.id }}" stocktype='defective'  data-id="{{ d.id }}" data-ordernum='{{ d.client_ordernum}}' data-json='{{ d.osJson }}' title="次品录入" class="layui-btn layui-btn-danger layui-btn-sm tail-stock-outin">次品录入</a><br>
		{{# if(d.tail_status==0){ }}
			<a href="javascript:void(0)" data-url="{:url('done')}?order_id={{ d.id }}" id="tail-done-{{ d.id }}" data-id="{{ d.id }}" data-json='{{ d.osJson }}' title="尾部完成" class="layui-btn layui-btn-sm tail-done">尾部完成</a><br>
		{{# } }}

	{if condition="env('mes_api_status') eq 1"}
		{{# if(d.delivery_sync_status==2){ }}
			<a href="javascript:void(0)" title="发货单同步中" class="layui-btn layui-btn-sm layui-btn-warm layui-btn-disabled">发货单同步中</a><br>
		{{# }else if(d.tail_status==1 || d.osStat.daohuo_count>0){ }}
			<a href="{:url('deliverySync')}?order_id={{ d.id }}" refresh=false id="delivery-sync-{{ d.id }}" callback="callbackDeliverySync" title="同步发货单" class="hisi-ajax layui-btn layui-btn-sm layui-btn-warm delivery-sync">同步发货单</a><br>
		{{# } }}
		{{# if(d.is_delivery==1){ }}
			<a href="{:url('deliveryList')}?order_id={{ d.id }}" title="查看发货单" class="hisi-iframe layui-btn layui-btn-sm layui-btn-primary">查看发货单</a><br>
		{{# } }}
	{/if}
		{{# if(d.tail_status==1){ }}
			{{# if(d.finishinfo==null){ }}
				<a href="javascript:void(0)" data-url="{:url('setOrderFinish')}?order_id={{ d.id }}" data-id="{{ d.id }}" in_store_count='' title="加入成品统计" class="layui-btn layui-btn-danger layui-btn-sm tail-defective">加入成品统计</a><br>
			{{# }else{ }}
				<a href="javascript:void(0)" data-url="{:url('setOrderFinish')}?order_id={{ d.id }}" data-id="{{ d.id }}" in_store_count='{{d.finishinfo.people_in_store_count}}' title="加入成品统计" class="layui-btn layui-btn-sm layui-btn-primary tail-defective">已加入成品统计</a><br>
			{{# } }}
		{{# } }}

	</div>
</script>

<div id="stockOutInTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
		{{#  for(var i in d.list){ }}
		<div class="layui-inline">
			<label class="layui-form-label">{{ d.list[i].size_name }}</label>
			<div class="layui-input-inline">
				<input type="text" name="number[{{ d.list[i].mid }}]" value="" lay-verify="number|required" placeholder="输入数量" class="layui-input">
			</div>
		</div>
		{{#  } }}
		
		<input type="hidden" name="order_id" value="{{ d.order_id }}">
		<input type="hidden" name="url" value="{{ d.url }}">
		<div class="layui-inline fr">
          <button class="layui-btn" lay-submit lay-filter="stock-out-in" >确认</button>
        </div>
	</div>
	</form>
</div>


<div id="StockCheckIn" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
    	<div align="center">
		{{#  for(var i in d.list){ }}
			<label class="layui-btn layui-btn-danger show_code_input" size_name="{{ d.list[i].size_name }}">{{ d.list[i].size_name }}</label>
		{{#  } }}
        </div>
        <div class="scan_code hide">
          <div class="dress_line_code">
            当前录入的尺码：<span class="size_name_span">___</span>，数量：<span class="checkInNumSpan">0</span>件 (注意：一个条码为一件)<br />
            <textarea name="dress_line_code" id="dress_line_code" class="layui-area code_input" lay-verify="" placeholder="扫服装条码"></textarea>
          </div>
          <div class="defective_reason">次品原因：<input type="text" name="defective_reason" value="" placeholder="输入次品原因(非必填)">
          <input type="hidden" name="stocktype" class="stocktype_input" value="">
          </div>
          <div class="submit_block">
            <button class="layui-btn" lay-submit lay-filter="stock-out-in" >确认入库</button>
          </div>
      </div>
      <div class="checkin_ret hide">处理结果：尺码：<span class="size_name_span"></span>，数量：<span class="checkInNumSpan">0</span>件，入库成功；<br />
      当前订单该尺码总库存：<span class="total_stock"></span>件<br />
	可选择其它尺码继续录入</div>
      <div>
      	&nbsp;
      </div>
		<input type="hidden" name="order_id" value="{{ d.order_id }}">
		<input type="hidden" name="url" value="{{ d.url }}">
        <input type="hidden" name="size_name" class="size_name_input" value="" lay-reqText="尺码请选择">
        <input type="hidden" name="number" value="" lay-verify="required" lay-reqText="请扫描服装条码"  class="layui-input checkinNum">
		<div>&nbsp;</div>
	</div>
	</form>
</div>

<div id="StockCheckOut" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
        <div class="scan_code">
          <div class="dress_line_code">
            请扫描要出库的服装：(注：一行一个服装条码)<br />
            <textarea name="out_dress_line_code" id="out_dress_line_code" class="layui-area out_code_input" lay-verify="" placeholder="扫描要出库的服装条码"></textarea>
            <input type="hidden" name="sku_stock" class="sku_stock" value='{{d.sku_stock}}'>
          </div>
          <div class="scan_code_block">验证提示：<span class="scan_code_ret"></span></div>
          <div class="submit_block">
            <button class="layui-btn" lay-submit lay-filter="stock-out-out" >确认出库</button>
          </div>
      </div>
      <div class="checkin_ret hide">处理结果：<span class="act_ret_str"></span>出库成功；<br /></div>
      <div>
      	&nbsp;
      </div>
		<input type="hidden" name="order_id" value="{{ d.order_id }}">
		<input type="hidden" name="url" value="{{ d.url }}">
        <input type="hidden" name="size_name" class="size_name_input" value="" lay-reqText="尺码请选择">
        <input type="hidden" name="number" value="" lay-verify="required" lay-reqText="请扫描要出库的服装条码"  class="layui-input outcheckinNum">
		<div>&nbsp;</div>
	</div>
	</form>
</div>


<div id="defectiveTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
    	<div class="layui-inline">
			<label class="layui-form-label">订单总入仓数：</label>
			<div class="layui-input-inline">
				<input type="text" name="people_in_store_count" value="{{d.in_store_count}}" style="width:120px;display:inline;" placeholder="输入数量" class="layui-input">&nbsp;件
			</div>
		</div>
        <div style="margin-top:5px;color:#666666;margin-bottom:15px;">注：不填总入仓数则统计所有子单入仓数</div>
		
		<input type="hidden" name="order_id" value="{{ d.order_id }}">
		<input type="hidden" name="url" value="{{ d.url }}">
		<div class="layui-inline fr">
          <button class="layui-btn" lay-submit lay-filter="stock-defective" >确认</button>
        </div>
	</div>
	</form>
</div>

<div id="doneTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
		{{#  for(var i in d.list){ }}
		<div class="layui-inline">
			<label class="layui-form-label">{{ d.list[i].size_name }}</label>
			<div class="layui-input-inline">
				<input type="text" name="number[{{ d.list[i].mid }}]" value="{{# if(d.list[i].jiaohuo_tail_count>0){ }}{{ d.list[i].jiaohuo_tail_count }}{{#  } }}" lay-verify="number|required" placeholder="输入数量" class="layui-input">
			</div>
		</div>
		{{#  } }}
		
		<input type="hidden" name="order_id" value="{{ d.order_id }}">
		<input type="hidden" name="url" value="{{ d.url }}">
		<div class="layui-inline fr">
          <button class="layui-btn layui-btn-normal" lay-submit lay-filter="save" >保存</button>
          <button class="layui-btn" lay-submit lay-filter="done" >确认并完成</button>
        </div>
	</div>
	</form>
</div>

<script type="text/html" id="deliveryStatusTpl">
	{{# if(d.is_delivery==1){ }}
		{{# for(var i in d.delivery_list){ }}
			{{delivery_status[d.delivery_list[i]]}} <br>
		{{# } }}
	{{# }else{ }}
			<span>无</span>
	{{# } }}

</script>
<script type="text/javascript">
	var factoryKV = {:json_encode($factoryKV);};
	var groupKV = {:json_encode($groupKV);};
	var orderFrom = {:json_encode($orderFrom);};
	var delivery_status={:json_encode($delivery_status);};
	groupKV['0'] = '请选择';
	
	layui.use([ 'opTable', 'jquery', 'tool', 'laydate', 'laytpl', 'form'], function() {
		var $ = layui.jquery;
		var laytpl = layui.laytpl;
		var form = layui.form;
		var laydate = layui.laydate;
		
		laydate.render({
		    elem: '#create_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range').val(value);
            	$('#layui-laydate1').remove();//关闭面板
            }
		});
		laydate.render({
		    elem: '#over_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
		    ,change: function(value, date, endDate){
		    	$('#over_date_range').val(value);
            	$('#layui-laydate2').remove();//关闭面板
            }
		});
		
		
		laydate.render({
		    elem: '#caichuang_over_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
		    ,change: function(value, date, endDate){
		    	$('#caichuang_over_date_range').val(value);
            	$('#layui-laydate3').remove();//关闭面板
            }
		});
		laydate.render({
		    elem: '#tail_over_time'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
		    ,change: function(value, date, endDate){
		    	$('#tail_over_time').val(value);
            	$('#layui-laydate4').remove();//关闭面板
            }
		});
		
		var opTable = layui.opTable.render({
			elem : '#dataTable'
			,url : '{:url()}'
			,page: true
			,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
			,openVisible: false
			,toolbar: '#toolbar'
	        ,defaultToolbar: ['filter', 'exports', 'print']
			,cols : [[ 
				{field:'pic',title : '图片', templet:'#picTpl',width:110}
				,{field:'client_ordernum',title : '订单号/SKU/时效', templet:'#skuTpl',width:162}
				,{field:'factory_id',title : '工厂/分组', templet:'#factoryTpl',width:150}
				,{field:'order_num',title : '下单 / 裁床 / 车间 / 后整 / 打包 / 出货 / 未出货', templet:'#orderNumTpl',width:290}
				,{field:'order_time',title : '时间进度', templet:'#orderTimeTpl',width:220}
				,{field:'order_user',title : '采购/裁床执行人', templet:'#orderUserTpl'}
				,{field:'order_user',title : '发货子单状态', templet:'#deliveryStatusTpl'}
				,{field:'stock',title : '其它单库存', templet:'#otherStockTpl'}
				,{field:'stock',title : '该单库存正/次品', templet:'#stockTpl'}
				,{field:'',title : '操作',templet:'#buttonTpl',width:150}
			]]
		});
		
		// 库存录入
		var layerStockOutIn = null;
		$(document).on('click','.tail-stock-outin',function(){
			var orderId = $(this).attr('data-id'),title=$(this).attr('title'),stocktype=$(this).attr("stocktype");
			var orderNum=$(this).attr('data-ordernum');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			
			var d = [];
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			$(".size_name_span").html("__");
			$(".size_name_input").val('');
			$(".scan_code").hide();
			$(".defective_reason").css("display",stocktype=='defective'?'block':'none'); 
			$(".stocktype_input").val(stocktype); 
			var content = laytpl($('#StockCheckIn').html()).render(d);
			layerStockOutIn = layer.open({
				type: 1
				,area: ['650px','350px']
				,offset: '100px'
				//,shade:[0.8, '#393D49']
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:title+'-当前入库的订单号：'+orderNum
				,content: content
			});
		});
		
		var sku_stock='';
		$(document).on('click','.tail-stock-out',function(){
			var orderId = $(this).attr('data-id');
			var orderNum=$(this).attr('data-ordernum');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var d = [];
			sku_stock = eval("(" + json+ ")");
			d['sku_stock']=json;
			d['url'] = url;
			d['order_id'] = orderId;
			$(".size_name_span").html("__");
			$(".size_name_input").val('');
			$(".scan_code").show();
			$(".checkin_ret").hide();
			$(".out_code_input").focus();
			var content = laytpl($('#StockCheckOut').html()).render(d);
			layerStockOut = layer.open({
				type: 1
				,area: ['660px','320px']
				,offset: '100px'
				//,shade:[0.8, '#393D49']
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'库存调用-你选择占用库存的订单号：'+orderNum
				,content: content
				,success:function(layerdom,index){
					$(".out_code_input").eq(1).focus();
				}
			});
		});
		$(document).on('input propertychange',".out_code_input", function() {
			var dress_line_code=$(this).val();
			if(dress_line_code==''){
				return;
			}
			var code_str=',';
			for(var i=0;i<sku_stock.length;i++){
				//alert(sku_stock[i]['dress_line_code']);
				code_str+=sku_stock[i]['dress_line_code']+",";
			}
			if(dress_line_code.length==17){
				dress_line_code=dress_line_code+"\n";
			}
			var codeNumbers=dress_line_code.split("\n");
			var last_input=codeNumbers[codeNumbers.length-1];
			var r, re;         
			var re = eval('/'+last_input+'/ig');
			r = dress_line_code.match(re);   //匹配字符
			$(".scan_code_ret").html('')
			for(var i=0;i<codeNumbers.length;i++){
				if(code_str.indexOf(codeNumbers[i])!=-1){

				}else{
					$(".scan_code_ret").eq(1).html("未找到"+codeNumbers[i]+"的库存信息或该条码不属于当前sku");
				}
			}
			if(codeNumbers[codeNumbers.length-1].length>=17){
				//$(".code_input").eq(1).val(dress_line_code+'\n');
			}
			$(".outcheckinNum").val(codeNumbers.length);
			$(".checkInNumSpan").html(codeNumbers.length);
		});
		
		$(document).on('click','.show_code_input',function(){
			$(".size_name_span").html($(this).attr('size_name'));
			$(".size_name_input").val($(this).attr('size_name'));
			$(".checkInNumSpan").html(0);
			$(".scan_code").show();
			$(".checkin_ret").hide();
			$(".code_input").eq(1).val('');
			$(".code_input").eq(1).focus();
		});
		$(document).on('input propertychange',".code_input", function() {
			var dress_line_code=$(this).val();
			if(dress_line_code==''){
				return;
			}
			var codes=dress_line_code.replace(/\n/g,"");
			var input_count=0;
			codes=codes.replace(/\r/g,"");
			var codeNumbers=codes.split(";");
			if(codeNumbers[codeNumbers.length-1].length>=17){
				$(".code_input").eq(1).val(codes+';');
				input_count=1;
			}
			$(".checkinNum").val(codeNumbers.length-1+input_count);
			$(".checkInNumSpan").html(codeNumbers.length-1+input_count);
			
		});
		
		form.on('submit(stock-out-in)', function (data) {
			console.log(data.field);
			var url = data.field.url;
			$.ajax({
	 		   type: "POST",
	 		   url: url,
	 		   data: data.field,
	 		   dataType:"json",
	 		   success: function(res){
	 			  if (res.code == 1) {
	 				 $('#StockCheckIn form')[0].reset();
	 				 //layer.close(layerStockOutIn);
					 $(".total_stock").html(res.data.available_count);
					 $(".checkInNumSpan").html(res.data.checkin_count);
					 $(".scan_code").hide();
					 $(".checkin_ret").show();
					 $(".checkinNum").eq(0).val('');
					 $(".checkinNum").eq(1).val('');
					 layer.msg(res.msg, {icon: 1,end:function(){
					 	//opTable.reload();
					 }});
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
	 		   }
	 		});
			
			return false;
		});
		
		form.on('submit(stock-out-out)', function (data) {
			console.log(data.field);
			var url = data.field.url;
			$.ajax({
	 		   type: "POST",
	 		   url: url,
	 		   data: data.field,
	 		   dataType:"json",
	 		   success: function(res){
	 			  if (res.code == 1) {
	 				 $('#stockOutInTpl form')[0].reset();
					 $(".total_stock").html(res.data.available_count);
					 $(".scan_code").hide();
					 $(".checkin_ret").show();
					 $(".act_ret_str").html(res.data.act_ret_str);
					 layer.msg(res.msg, {icon: 1,end:function(){
					 	opTable.reload();
						layer.close(layerStockOut);
					 }});
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
	 		   }
	 		});
			return false;
		});
		
		// 次品录入
		var layerDefective = null;
		$(document).on('click','.tail-defective',function(){
			var orderId = $(this).attr('data-id');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var in_store_count=$(this).attr('in_store_count');
			var d = [];
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			d['in_store_count']=in_store_count;
			var content = laytpl($('#defectiveTpl').html()).render(d);
			layerDefective = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'确认加入成品统计'
				,content: content
			});
		});
		form.on('submit(stock-defective)', function (data) {
			console.log(data.field);
			var url = data.field.url;
			$.ajax({
	 		   type: "POST",
	 		   url: url,
	 		   data: data.field,
	 		   dataType:"json",
	 		   success: function(res){
	 			  if (res.code == 1) {
	 				 $('#defectiveTpl form')[0].reset();
	 				 layer.close(layerDefective);
					 layer.msg(res.msg, {icon: 1,end:function(){opTable.reload();}});
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
	 		   }
	 		});
			
			return false;
		});

		// 尾部完成
		var layerDone = null;
		$(document).on('click','.tail-done',function(){
			var orderId = $(this).attr('data-id');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var d = [];
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			var content = laytpl($('#doneTpl').html()).render(d);
			layerDone = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'后整数录入'
				,content: content
			});
		});
		// 尾部数据保存
		form.on('submit(save)', function (data) {
			var url = data.field.url;
			$.ajax({
	 		   type: "POST",
	 		   url: url,
	 		   data: data.field,
	 		   dataType:"json",
	 		   success: function(res){
	 			  if (res.code == 1) {
	 				 $('#doneTpl form')[0].reset();
	 				 layer.close(layerDone);
					 layer.msg(res.msg, {icon: 1,end:function(){reloadTable();}});
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
	 		   }
	 		});
			return false;
		});
		
		// 尾部确认完成
		form.on('submit(done)', function (data) {
			var url = data.field.url;
			$.ajax({
	 		   type: "POST",
	 		   url: url+"&is_done=1",
	 		   data: data.field,
	 		   dataType:"json",
	 		   success: function(res){
	 			  if (res.code == 1) {
	 				 $('#doneTpl form')[0].reset();
	 				 layer.close(layerDone);
					 layer.msg(res.msg, {icon: 1,end:function(){reloadTable();}});
				  } else {
					 layer.msg(res.msg, {icon: 2,anim: 6});
				  }
	 		   }
	 		});
			return false;
		});
		
		// 申请同步发货单回调
		window.callbackDeliverySync = function(obj, res) {
			if (res.code == 1) {
				var orderId = res.data.order_id;
				$('#delivery-sync-'+orderId).before('<a href="javascript:void(0)" title="发货单同步中" class="layui-btn layui-btn-sm layui-btn-warm layui-btn-disabled">发货单同步中</a>');
				$('#delivery-sync-'+orderId).remove();
			}
		};
		
		/**
	     * layui非静态table搜索渲染
	     * @attr data-table table容器ID
	     * @attr hisi-data table基础参数
	     * @attr action 搜索请求地址
	     */
	   $(document).on('submit', '#hisiSearchOpTable,#hisi-table-search-optable', function() {
	        var that = $(this), 
	            arr = that.serializeArray(), 
	            where = new Array(),
	            dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
	            options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:1}};
	        
	            for(var i in arr) {
	                where[arr[i].name] = arr[i].value;
	            }
	        
	        options.url = that.attr('action');
	        options.where = where;
	        
	        opTable.reload(options);
	        return false;
	    });
	
		// 刷新当前页
		window.reloadTable = function () {
			var that = $("#hisi-table-search-optable"), 
	            arr = that.serializeArray(), 
	            where = new Array(),
	            dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',
	            currPage = $(".layui-laypage-em").next().html(),
	            options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
            for(var i in arr) {
                where[arr[i].name] = arr[i].value;
            }
        
	        options.url = that.attr('action');
	        options.where = where;
	        
	        opTable.reload(options);
	        return false;
		}
	});
</script>